// JavaScript Document
$(function(){
	UserLayer();
	Checkbox();
	$("#slide").slide({otrue:true,speed2:2000});
});
var Checkbox =function(){
	var btn = $(".SimulationCheckbox"),
	$true = true;
	btn.on("click",function(){
		if($true == true){
			$(this).removeClass("checked");
			$true = false;
		}else{
			$(this).addClass("checked");
			$true = true
		};
	});
	
};
var UserLayer = function(){
	var $btn = $(".UserHP"),
	$Layer = $(".UserLayer"),	
	timer = null,
	t = 0,	l = 0;
	$btn.on("mouseover",function(){
		clearTimeout(timer);
		l = $(this).position().left;
		t = $(this).position().top + $(".hear").height();
		$Layer.css({"left":l,"top":t}).show();
	});
	$btn.on("mouseout",function(){
		timer = setTimeout(function(){
			$Layer.hide();
		},200);
		
	});
	$Layer.on("mouseover",function(){
		clearTimeout(timer);
		l = $btn.position().left;
		t = $btn.position().top + $(".hear").height();
		$(this).css({"left":l,"top":t}).show();
	});
	$Layer.on("mouseout",function(){
		$(this).hide();
	});
};
(function ($){
	$.fn.slide = function (options){
		var defaults = {    
			oEvent: "click",
			oBtn:".slide-btn",
			oprc:".slide-prc",
			oList:".list",
			oAdd: "active",
			oprev:".prev",
			onext:".next",
			speed:800,
			speed2:3000,
			otrue:true
		};
        var opts = $.extend(defaults, options);
        return this.each(function() {
			 var $this = $(this);
			 var $btnMn = $this.find(opts.oBtn);
			 var $btn = $btnMn.find("a");
			 var $prev = $this.find(opts.oprev);
			 var $next = $this.find(opts.onext);
			 var $list = $this.find(opts.oList);
			 var $prcMnUl = $this.find(opts.oprc).find("ul");
			 var $width = $list.outerWidth(true);
			 var speed = opts.speed;
			 var Add = opts.oAdd;
			 var index = 0;
			 var old = 0;
			 $prcMnUl.css({left: "0px"});
    		 $list.not(":first").hide();
			 function noMove() {
				if (!$prcMnUl.is(":animated")) {
					return true;
				} else {
					return false;
				}; 
			 };
			 $btn.bind(opts.oEvent,function (){
				 if(noMove()){
					 index=$(this).index();
					 old=$btnMn.find("a.active").index();
					 if(index>old){
						 move(index,-1)
					 }else if(index<old){
						 move(index,1)
					 }else{
						return false;	 
					 }
					 
				 }
			 });
			 $prev.bind("click" ,function () {
				 if(noMove()){
					 index=$btnMn.find("a.active").index();
					 if(index==0){
						index=$list.length-1;
						move($list.length-1,1);
					 }else{
						 $btnMn.find("a.active").prev().trigger(opts.oEvent);
					 }
				 }
			 });
			 $next.bind("click" ,function () {
				 if(noMove()){
					 index=$btnMn.find("a.active").index();
					 if(index==$list.length-1){
						index=0;					
						move(0,-1);
					 }else{
						 $btnMn.find("a.active").next().trigger(opts.oEvent);
					 }
				 }
			 });
			function move(index,is) {//- +
				$btn.eq(index).addClass(Add).siblings().removeClass(Add);
				$list.eq(index).show(0).css({left: is*-$width + "px"});
				$(".recommend div.dib").eq(index).fadeIn().siblings().fadeOut();
				$prcMnUl.animate({left: is*$width + "px"},speed,function() {
					$list.eq(index).css({left: "0px"}).siblings().hide();
					$prcMnUl.css({left: "0px"});
				});
			};
			if(opts.otrue){
			var autoScroll=setInterval(function(){
				$next.trigger("click")
			},opts.speed2);
			var autoPlay=function(){
				autoScroll=setInterval(function(){
				$next.trigger("click")
				},opts.speed2);
			};
			var stopPlay=function(){
				clearInterval(autoScroll);
			};
			$this.hover(stopPlay,autoPlay);
			}
		});
		return this;
	};
})(jQuery);